<?php
namespace App\Http\Controllers\zb;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;

class zbController extends Controller{
    public function fl(){
                $info =DB::table('zbfl')->get();
                return view('zb/fl',['info'=>$info]);
    }
   public function edit(Request $r){
                // print_r($_POST);die();
                if ($r->isMethod('post')){
                        $data=$r->all();
                       unset($data['_token']);
           $info=DB::table('zbfl')->where('id',$data['id'])->update($data);
           if ($info){
                              return redirect('zb_fl');
           }else{
                                dd("修改失败");
                         }
       }else{
                     $id=$_GET['id'];
                        // var_dump($id);die();
                       $info=DB::table('zbfl')->where('id',$id)->first();
                    //dd($info);die;
                     return view('zb/edit',['info'=>$info]);
                }
    }

    public function del(){
                $id = $_GET;
                $data = DB::table('zbfl')->where(['id' => $id])->delete();
                if ($data) {
                        return redirect('zb_fl');
        } else {
                       return view('zb/fl');
        }
   }

    public function addlist(Request $request){
               if($_POST){

                        $path = "img/{$_FILES['face']['name']}";
                       //实现图片上传
                        move_uploaded_file($_FILES['face']['name'],$path);
                        $array = array('name' => $_POST['name'],'face'=>$_POST['face']=$path);
                        $info = DB::table('zbfl')->insert($array);
                        if($info){
                                return redirect('zb_fl');
            }
        }else{
                        return view('zb/addlist');
        }
    }


   public function lwlist(){
        if($_POST){
            $path = "img/{$_FILES['face']['name']}";
            //实现图片上传
            move_uploaded_file($_FILES['face']['name'],$path);
            $array=array('type'=>$_POST['type'],'bs'=>$_POST['bs'],'name'=>$_POST['name'],'num'=>$_POST['num'],$_POST['face']=>$path,'face_type'=>$_POST['face_type'],$_POST['dh']=>$path,'dh_time'=>$_POST['dh_time'],'fb_time'=>$_POST['fb_time']);
            $info = DB::table('zblw')->insert($array);
            if($info){


                 return redirect('zb/lw');
            }
        }else{
            return view('zb/lw');
        }
    }
}